package org.sample.pattern.singleton;

/** 单例模式的双检查-懒汉式实现 */
public class SingletonDoubleCheck {

    /** volatile 关键字 防止指定重排 以及 实时的内存可见性 */
    private static volatile SingletonDoubleCheck Instance = null;

    private SingletonDoubleCheck() {
    }

    public static SingletonDoubleCheck getInstance() {
        if (Instance == null) {
            synchronized (SingletonDoubleCheck.class) {
                if (Instance == null)
                    Instance = new SingletonDoubleCheck();
            }
        }
        return Instance;
    }
}